package com.pinc.wacow;

import android.content.Context;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.pinc.wacow.R;

public class CheckedQuestionItem extends RelativeLayout implements Checkable {
	private LayoutInflater mInflater;
	private RelativeLayout mTop;
	private boolean mBoolean;
	private ImageView iv_mark;
	private TextView tv_q;
	private TextView tv_qpos;
	private TextView tv_f;

	public CheckedQuestionItem(Context context) {
		super(context);
		mInflater = LayoutInflater.from(context);
		mTop = (RelativeLayout) mInflater.inflate(R.layout.question_item, this);
		iv_mark = (ImageView) mTop.findViewById(R.id.imageView_add);
		tv_qpos = (TextView) mTop.findViewById(R.id.textView_Qpos);
		tv_q = (TextView) mTop.findViewById(R.id.textView_question);
		tv_f = (TextView) mTop.findViewById(R.id.textView_fault);
	}

	public void setTextQ(String str)
	{
		tv_q.setText(str);
	}

	public void setTextQ(Spanned str)
	{
		tv_q.setText(str);
	}

	public void setTextF(String str)
	{
		tv_f.setText(str);
	}

	public void setTextPos(String str)
	{
		tv_qpos.setText(str);
	}

	@Override
	public boolean isChecked() {
		return mBoolean;
	}

	@Override
	public void setChecked(boolean checked) {
		mBoolean = checked;
		updateMark();
	}

	@Override
	public void toggle() {
		mBoolean = !mBoolean;
		updateMark();
	}

	private void updateMark()
	{
		if ( mBoolean)
			iv_mark.setImageResource(R.drawable.add);
		else
			iv_mark.setImageResource(R.drawable.addx);
	}
}
